home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Orlando_1993 / Devcon93.4 / CAMD / examples / trans / selectnode.a < prev    next >
Encoding:
Text File  |  1992-12-26  |  1.5 KB  |  60 lines

  1. ******* ibox.lib/SelectNode *************************************************
  2. *
  3. *   NAME
  4. *       SelectNode -- select the Nth node from an Exec List
  5. *
  6. *   SYNOPSIS
  7. *       node = SelectNode( list, index )
  8. *       D0                 a0    d1
  9. *
  10. *       struct Node * __asm SelectNode( register __a0 struct List *,
  11. *                                       register __d1 WORD );
  12. *
  13. *   FUNCTION
  14. *       Selects a node in an Exec list by numerical position in the list.
  15. *
  16. *   INPUTS
  17. *       list        - pointer to List or MinList
  18. *       index       - the number of the element to select.
  19. *
  20. *   RESULT
  21. *       node        - the address of the node, or NULL if the index is
  22. *                     larger than the last node in the list.
  23. *
  24. *   EXAMPLE
  25. *
  26. *   NOTES
  27. *
  28. *   BUGS
  29. *
  30. *   SEE ALSO
  31. *       exec/lists.h, exec/nodes.h
  32. *
  33. *****************************************************************************
  34. *    Written by Joe Pearce. Modified for SAS/DICE by Talin
  35. *
  36.             include 'exec/lists.i'
  37.  
  38.             SECTION        text,CODE
  39.  
  40.             xdef    _SelectNode,@SelectNode
  41.  
  42. _SelectNode:
  43.             move.l    4(sp),a0                ; get list
  44.             move.l    8(sp),d1                ; get index
  45. @SelectNode:
  46.             moveq    #0,d0                    ; prime for error return
  47.  
  48. ; note since list heads are also nodes, we can just use the LN_SUCC field.
  49.  
  50. loop:        move.l    LN_SUCC(a0),a0            ; go to first/next node
  51.             tst.l    LN_SUCC(a0)                ; is this really the header?
  52.             beq.s    no_node                    ; yep, so return NULL
  53.  
  54.             dbra    d1,loop                    ; loop till we drop
  55.  
  56.             move.l    a0,d0                    ; found a valid node at index
  57. no_node:    rts
  58.  
  59.             end
  60.